package com.example.book.controller;

import com.example.book.common.Constants;
import com.example.book.common.Result;
import com.example.book.entry.User;
import com.example.book.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RequestMapping("/user")
@RestController
public class UserController {

    @Autowired
    private IUserService userService;

//    登录
    @PostMapping("/login")
    public Result login(@RequestBody User user){
        Result result = userService.login(user);
        return result;
    }

//    注册
    @PostMapping("/register")
    public Result register(@RequestBody User user){
        Result result = userService.userRegister(user);
        return result;
    }

//    根据id查询用户信息
    @GetMapping("/id={id}")
    public Result getUserOne(@PathVariable Integer id){
        User byId = userService.getById(id);
        return Result.success(byId);
    }

//    修改用户信息
    @PostMapping("/update")
    public Result updateUser(@RequestBody User user){
        userService.saveOrUpdate(user);
        return Result.success("success");
    }
}
